﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.geom.*;
    import org.aswing.event.*;
    import org.aswing.plaf.basic.*;

    public class JScrollPane extends Container {

        public static const SCROLLBAR_AS_NEEDED:int = 0;
        public static const SCROLLBAR_NEVER:int = 1;
        public static const SCROLLBAR_ALWAYS:int = 2;

        private var viewport:Viewportable;
        private var vScrollBar:JScrollBar;
        private var hScrollBar:JScrollBar;
        private var vsbPolicy:int;
        private var hsbPolicy:int;

        public function JScrollPane(_arg1=null, _arg2:int=0, _arg3:int=0){
            setName("JScrollPane");
            this.vsbPolicy = _arg2;
            this.hsbPolicy = _arg3;
            this.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL));
            this.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
            if (_arg1 != null){
                this.setView(_arg1);
            } else {
                this.setViewport(new JViewport());
            };
            this.setLayout(new ScrollPaneLayout());
            this.updateUI();
        }
        override public function updateUI():void{
            setUI(UIManager.getUI(this));
        }
        override public function getDefaultBasicUIClass():Class{
            return (BasicScrollPaneUI);
        }
        override public function getUIClassID():String{
            return ("ScrollPaneUI");
        }
        override public function setLayout(_arg1:LayoutManager):void{
            if ((_arg1 is ScrollPaneLayout)){
                super.setLayout(_arg1);
            } else {
                throw (new ArgumentError("Only can set ScrollPaneLayout to JScrollPane"));
            };
        }
        override public function isValidateRoot():Boolean{
            return (true);
        }
        public function setView(_arg1):void{
            if ((_arg1 is Viewportable)){
                this.setViewport(Viewportable(_arg1));
            } else {
                if ((_arg1 is Component)){
                    this.setViewportView(Component(_arg1));
                } else {
                    throw (new TypeError("Only accept Component or Viewportable instance here!"));
                };
            };
        }
        public function setViewportView(_arg1:Component):void{
            var _local2:JViewport = (this.getViewport() as JViewport);
            if (_local2 != null){
                _local2.setView(_arg1);
            } else {
                this.setViewport(new JViewport(_arg1));
            };
        }
        public function getViewportView():Component{
            var _local1:JViewport = (this.getViewport() as JViewport);
            if (_local1 != null){
                return (_local1.getView());
            };
            return (null);
        }
        public function setViewport(_arg1:Viewportable):void{
            if (this.viewport != _arg1){
                if (this.viewport != null){
                    remove(this.viewport.getViewportPane());
                };
                this.viewport = _arg1;
                if (this.viewport != null){
                    insertImp(-1, this.viewport.getViewportPane());
                };
                revalidate();
                dispatchEvent(new ScrollPaneEvent(ScrollPaneEvent.VIEWPORT_CHANGED, true, null, true));
            };
        }
        public function getViewport():Viewportable{
            return (this.viewport);
        }
        public function getVisibleRect():IntRectangle{
            return (new IntRectangle(this.getHorizontalScrollBar().getValue(), this.getVerticalScrollBar().getValue(), this.getHorizontalScrollBar().getVisibleAmount(), this.getVerticalScrollBar().getVisibleAmount()));
        }
        public function addAdjustmentListener(_arg1:Function, _arg2:int=0, _arg3:Boolean=false):void{
            addEventListener(ScrollPaneEvent.SCROLLBAR_STATE_CHANGED, _arg1, false, _arg2);
        }
        public function removeAdjustmentListener(_arg1:Function):void{
            removeEventListener(ScrollPaneEvent.SCROLLBAR_STATE_CHANGED, _arg1);
        }
        private function __onBarScroll(_arg1:InteractiveEvent):void{
            dispatchEvent(new ScrollPaneEvent(ScrollPaneEvent.SCROLLBAR_STATE_CHANGED, _arg1.isProgrammatic(), JScrollBar(_arg1.target), false));
        }
        public function setHorizontalScrollBar(_arg1:JScrollBar):void{
            if (this.hScrollBar != _arg1){
                if (this.hScrollBar != null){
                    this.hScrollBar.removeStateListener(this.__onBarScroll);
                    remove(this.hScrollBar);
                };
                this.hScrollBar = _arg1;
                if (this.hScrollBar != null){
                    this.hScrollBar.setName("HorizontalScrollBar");
                    insertImp(-1, this.hScrollBar);
                    this.hScrollBar.addStateListener(this.__onBarScroll);
                };
                revalidate();
            };
        }
        public function getHorizontalScrollBar():JScrollBar{
            return (this.hScrollBar);
        }
        public function setHorizontalScrollBarPolicy(_arg1:Number):void{
            this.hsbPolicy = _arg1;
        }
        public function getHorizontalScrollBarPolicy():Number{
            return (this.hsbPolicy);
        }
        public function setVerticalScrollBar(_arg1:JScrollBar):void{
            if (this.vScrollBar != _arg1){
                if (this.vScrollBar != null){
                    this.vScrollBar.removeStateListener(this.__onBarScroll);
                    remove(this.vScrollBar);
                };
                this.vScrollBar = _arg1;
                if (this.vScrollBar != null){
                    this.vScrollBar.setName("verticalScrollBar");
                    insertImp(-1, this.vScrollBar);
                    this.vScrollBar.addStateListener(this.__onBarScroll);
                };
                revalidate();
            };
        }
        public function getVerticalScrollBar():JScrollBar{
            return (this.vScrollBar);
        }
        public function setVerticalScrollBarPolicy(_arg1:Number):void{
            this.vsbPolicy = _arg1;
        }
        public function getVerticalScrollBarPolicy():Number{
            return (this.vsbPolicy);
        }
        override public function append(_arg1:Component, _arg2:Object=null):void{
            this.setView(_arg1);
        }
        override public function insert(_arg1:int, _arg2:Component, _arg3:Object=null):void{
            this.setView(_arg2);
        }
        override protected function getFocusTransmit():Component{
            return (this.getViewport().getViewportPane());
        }

    }
}//package org.aswing 
